<template>
  <div class="container">
    <div>
      <div class="btn_container">
        <div class="refreshBtn" @click="getList">
          <el-icon>
            <Refresh />
          </el-icon>
        </div>
      </div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="账号名称">
          <el-input
            v-model="formInline.name"
            placeholder="请输入账号名称"
            style="width: 240px"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="ID" />
      <el-table-column prop="name" label="所属账户" width="155" />
      <el-table-column prop="collect" label="收藏数量" />
      <el-table-column prop="comment" label="评论数量" />
      <el-table-column prop="like" label="点赞数量" />
      <el-table-column prop="share" label="分享数量" />
      <el-table-column prop="show" label="浏览量" />
      <el-table-column prop="note_id" label="笔记ID" />
      <el-table-column prop="create_time" label="创建时间" />
      <el-table-column prop="update_time" label="更新时间" />
    </el-table>
    <div class="page_container">
      <el-pagination
        v-model:current-page="page"
        v-model:page-size="page_size"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, watch, computed } from "vue";
import { Refresh, ArrowDown } from "@element-plus/icons-vue";
import { note_list } from "@/api/xhs.js";
import { ElMessage } from "element-plus";
import moment from "moment";
const page_size = ref(10);
const page = ref(1);
const total = ref(0);
const tableData = ref([]);
const formInline = reactive({
  name: "",
});
const handleSearch = () => {
  const { name } = formInline;
  const params = {
    name,
  };
  getList(params);
};
const handleSizeChange = (val) => {
  page_size.value = val;
};
const handleCurrentChange = (val) => {
  page.value = val;
};
const getList = async (params) => {
  try {
    const res = await note_list({
      page_size: page_size.value,
      page: page.value,
      ...params,
    });
    if (res?.code === 0) {
      tableData.value = res.data.list;
      total.value = res.data.total;
    } else {
      ElMessage.error(res.msg);
    }
  } catch (err) {
    console.log(err);
  }
};
watch(
  [page_size, page],
  () => {
    getList();
  },
  {
    immediate: true,
  }
);
</script>
<style scoped lang="scss">
.btn_container {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
  .refreshBtn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #78d0ec63;
    color: #78d0ecf2;
    border-radius: 50%;
    margin-left: 10px;
    cursor: pointer;
  }
}
.container {
  width: 100%;
  height: 100%;
  padding: 50px;
  box-sizing: border-box;
}

.page_container {
  float: right;
  margin-top: 40px;
}

:deep(.el-table__header) {
  background-color: #f5f7fa !important;
}

:deep(.el-table tr) {
  background-color: rgba(0, 0, 0, 0);
}

:deep(.el-table th.el-table__cell) {
  background-color: rgba(0, 0, 0, 0);
}
</style>
